/**
 *chongzhi
 */

module game {
    export class CZ_VIPchongzhiPanel extends eui.Component {
        public page1: eui.Group;
        public userID: eui.Label;
        public copy: eui.Button;
        public toushu: eui.Button;
        public QQButtonGroup: eui.Group;

        public page2: eui.Group;
        public selectName: eui.Label;
        public QQNumber: eui.EditableText;
        public toushu2: eui.Button;
        public copy1: eui.Button;

        public conmitButton: eui.Button;
        public back: eui.Button;


        private data;
        private PayId = null;//渠道ID
        public constructor(data: Object) {
            super();
            this.data = data;
            this.addEventListener(egret.Event.COMPLETE, this.init, this)
            this.addEventListener(egret.Event.REMOVED, this.destroy, this)
            this.skinName = "resource/ui/game/CZ_PayServerInfoVIP.exml";
        }
        private btnArr: Array<eui.Button> = []
        private init() {
            this.userID.text = "" + GameVO.getVo().dwUserID;
            //生成QQ充值按钮
            this.btnArr = [];
            this.QQButtonGroup.removeChildren();
            var Wxs: Array<Object> = this.data["Wxs"];
            var leng = Wxs.length;
            for (var i = 0; i < leng; i++) {
                var obj = Wxs[i];
                var g = new eui.Group;
                var img = new eui.Image("chongzhi_xiaokuang")
                g.addChild(img)
                var lab = new eui.Label(obj["VIPName"])
                lab.width = 150;
                lab.horizontalCenter = 0;
                lab.textAlign = "center"
                lab.y = 20;
                g.addChild(lab);
                var btn = new eui.Button();
                btn.label = ""
                btn.icon = "chongzhi_qqcz"
                btn.touchEnabled = true
                btn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.btnClick, this)
                btn.horizontalCenter = 0;
                btn.y = 115;
                btn.name = obj["VIPID"]
                g.addChild(btn);
                this.btnArr.push(btn)
                this.QQButtonGroup.addChild(g);
            }
            //复制我的ID
            this.copy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.IDcopyClick, this)
            this.copy1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.copyClick, this)
            this.back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.sybClick, this)
            this.conmitButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.conmitClick, this)
            this.toushu.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tousuClick, this)
            this.toushu2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tousuClick2, this)
        }
        private destroy() {
            this.removeEventListener(egret.Event.REMOVED, this.destroy, this)
            var leng = this.btnArr.length
            for (var i = 0; i < leng; i++) {
                this.btnArr[i].removeEventListener(egret.TouchEvent.TOUCH_TAP, this.btnClick, this)
            }
            this.copy.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.IDcopyClick, this)
            this.copy1.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.copyClick, this)
            this.back.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.sybClick, this)
            this.conmitButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.conmitClick, this)
            this.toushu.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.tousuClick, this)
            this.toushu2.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.tousuClick2, this)
        }
        //点击复制ID
        private IDcopyClick() {
            copyText(this.userID.text)
            EffectUtils.textFadeAway("复制成功")
        }
        //复制
        private copyClick(eve: egret.TouchEvent) {
            var text = this.QQNumber.text
            copyText(text)
            EffectUtils.textFadeAway("复制成功")
        }
        //点击投诉
        private tousuClick() {
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TOUSU_KEFU)
        }
        //点击投诉
        private tousuClick2() {
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_TOUSU_KEFU, this.QQNumber.text)
        }
        //点击chongzhi按钮
        private btnClick(eve: egret.TouchEvent) {
            var button: eui.Button = eve.currentTarget;
            var qq = button.name;
            this.PayId = qq;
            this.page1.visible = false;
            this.page2.visible = true;

            var Wxs: Array<Object> = this.data["Wxs"];
            var leng = Wxs.length;
            for (var i = 0; i < leng; i++) {
                if (Wxs[i]["VIPID"] == qq) {
                    this.selectName.text = Wxs[i]["VIPName"];
                    this.QQNumber.text = Wxs[i]["VIPID"];
                    break;
                }
            }
        }
        //上一步
        private sybClick() {
            this.page1.visible = true;
            this.page2.visible = false;
        }
        //点击充值提交按钮
        private conmitClick(eve: egret.TouchEvent) {
            var PayId = this.PayId;
            //QQ号不为空就可以提交了
            window.open("tencent://AddContact/?fromId=45&fromSubId=1&subcmd=all&uin=" + PayId + "&website=www.oicqzone.com");
        }
    }
}